import { watch, ref } from "vue";

const urlKey = "mock_baseurl";
const enabledKey = "mock_enabled";
const mockEnabled = ref(false);
const mockUrl = ref(null);

if (import.meta.env.DEV) {
  mockEnabled.value = localStorage.getItem(enabledKey) == "true";
  mockUrl.value = localStorage.getItem(urlKey);
}

watch(() => mockEnabled.value, mockEnabled => {
  localStorage.setItem(enabledKey, mockEnabled ? "true" : "false");
});

watch(() => mockUrl.value, mockUrl => {
  localStorage.setItem(urlKey, mockUrl);
});

export { mockEnabled, mockUrl };
